﻿using AutoMapper;
using B.S.Meeting.Domain;
using B.S.Meeting.ErrorCode;
using B.S.Meeting.Infrastructure.Interfaces;
using B.S.Meeting.ReadAPI.Applications.Commands.MeetingRooms;
using MediatR;

namespace B.S.Meeting.ReadAPI.Applications.CommandHandlers.MeetingRooms
{
    public class SelectRoomCommandHandler : IRequestHandler<SelectRoomCommand, APIResult<IList<MeetingRoom>>>
    {
        IMapper mapper;
        IBaseRepository<MeetingRoom> mrRep;
        ILogger<SelectRoomCommandHandler> logger;

        public SelectRoomCommandHandler(IBaseRepository<MeetingRoom> mrRep, ILogger<SelectRoomCommandHandler> logger, IMapper mapper)
        {
            this.mrRep = mrRep;
            this.logger = logger;
            this.mapper = mapper;
        }

        public async Task<APIResult<IList<MeetingRoom>>> Handle(SelectRoomCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var list = mrRep.GetAll();
                return new APIResult<IList<MeetingRoom>>
                {
                    Code=StatusEnumCode.Ok,
                    Message="获取会议室位置成功",
                    Data=list.ToList()
                };
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
